package com.qf.hotel.dao.impl;

import com.qf.hotel.dao.MenuDao;
import com.qf.hotel.pojo.Menu;
import com.qf.hotel.utils.JdbcUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

/**
 * Menu持久层实现类
 */
public class MenuDaoImpl implements MenuDao {
    QueryRunner queryRunner = new QueryRunner(JdbcUtils.getDataSource());

    /**
     * 实现查询所有的操作
     * @return
     */
    @Override
    public List<Menu> findAll() throws SQLException {
        String sql = "select menu_id as menuId,menu_name as menuName,menu_url as menuUrl from t_menu";
        // 执行查询得到结果
        return queryRunner.query(JdbcUtils.getConnection(), sql, new BeanListHandler<>(Menu.class));
    }
}
